﻿using System;
using System.IO;

namespace Terraria.DataStructures
{
	// Token: 0x02000479 RID: 1145
	public class CachedBuffer
	{
		// Token: 0x170002AB RID: 683
		// (get) Token: 0x06002691 RID: 9873 RVA: 0x0001AD94 File Offset: 0x00018F94
		public int Length
		{
			get
			{
				return this.Data.Length;
			}
		}

		// Token: 0x170002AC RID: 684
		// (get) Token: 0x06002692 RID: 9874 RVA: 0x0001AD9E File Offset: 0x00018F9E
		public bool IsActive
		{
			get
			{
				return this._isActive;
			}
		}

		// Token: 0x06002693 RID: 9875 RVA: 0x00492190 File Offset: 0x00490390
		public CachedBuffer(byte[] data)
		{
			this.Data = data;
			this._memoryStream = new MemoryStream(data);
			this.Writer = new BinaryWriter(this._memoryStream);
			this.Reader = new BinaryReader(this._memoryStream);
		}

		// Token: 0x06002694 RID: 9876 RVA: 0x0001ADA6 File Offset: 0x00018FA6
		internal CachedBuffer Activate()
		{
			this._isActive = true;
			this._memoryStream.Position = 0L;
			return this;
		}

		// Token: 0x06002695 RID: 9877 RVA: 0x0001ADBD File Offset: 0x00018FBD
		public void Recycle()
		{
			if (this._isActive)
			{
				this._isActive = false;
				BufferPool.Recycle(this);
			}
		}

		// Token: 0x0400434B RID: 17227
		public readonly byte[] Data;

		// Token: 0x0400434C RID: 17228
		public readonly BinaryWriter Writer;

		// Token: 0x0400434D RID: 17229
		public readonly BinaryReader Reader;

		// Token: 0x0400434E RID: 17230
		private readonly MemoryStream _memoryStream;

		// Token: 0x0400434F RID: 17231
		private bool _isActive = true;
	}
}
